home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mnp_c.zip / TESTC.C < prev    next >
C/C++ Source or Header  |  1990-05-16  |  3KB  |  155 lines

  1. #include <stdio.h>
  2. #include <graph.h>
  3. #include <asynch_2.h>
  4. #include <asynch_m.h>
  5.  
  6. main ()
  7. {
  8. unsigned int com_port,
  9.     i,
  10.     no_read,
  11.     no_sent,
  12.     retcode,
  13.     status;
  14. unsigned char iobuf[200],
  15.     mresp[10],
  16.     md_cmd[40],
  17.     rcv_data[80];
  18.  
  19. unsigned char ch;
  20. POPT option_rec;
  21. MDPARM *parm;
  22.  
  23. struct
  24.     {
  25.     int p_stat;
  26.     int l_stat;
  27.     int s_cnt;
  28.     int r_cnt;
  29.      int all_sent;
  30.     } lstat;
  31.  
  32. /*--- Display herald screen 
  33. */
  34. _clearscreen(_GCLEARSCREEN);
  35. cprintf("-------------------------------------------------------------------");
  36. cprintf("----------\r\n\r\n");
  37. cprintf("                      MNP Link Demonstration Program\r\n\r\n");
  38. cprintf("      This simple terminal emulation program demonstrates the use");
  39. cprintf("\r\n");
  40. cprintf("      of the Microcom MNP Library to provide error-free data\r\n");
  41. cprintf("      communications.\r\n\r\n\r\n");
  42. cprintf("      Press any key to begin...\r\n\r\n");
  43. cprintf("-------------------------------------------------------------------");
  44. cprintf("----------\r\n\r\n");
  45.  
  46. /*--- Wait for user to start
  47. */
  48. ch=getch();
  49.  
  50. /*--- Get user parameter selections
  51. */
  52. com_port=2;
  53.  
  54. /*--- Open port
  55. */
  56. if (retcode = open_a2(com_port,50,50,0,0))
  57.     printf("attempt to open port failed-%c\n",retcode);
  58.  
  59. retop_a2(com_port,&option_rec);
  60. option_rec.baud_rate=2400;
  61. option_rec.data_bits=8;
  62. option_rec.stop_bits=1;
  63. option_rec.parity=0;
  64. setop_a2(com_port,&option_rec);
  65.  
  66. /*--- Initialize modem (Hayes 2400-compatible assumed)
  67. */
  68. parm_md(&parm);
  69. parm->mport_no=com_port;
  70. parm->resp_delay=19;
  71.  
  72. cmd_md("V0\\N0",&no_sent);
  73. wait_a1(parm->resp_delay);
  74.  
  75. /*--- Dial MNP-capable remote and wait for connect
  76. */
  77. iflsh_a1(parm->mport_no);
  78.  
  79. cprintf("dialing Compuserv at 902-0488...\n\r");
  80. cmd_md("dt9020488",&no_sent);
  81.  
  82. wait_a1(parm->resp_delay);
  83. iflsh_a1(parm->mport_no);
  84.  
  85. for (i=0;i<30;i++)
  86.     {
  87.     retcode=resp_md(mresp,2,&no_read);
  88.     if (no_read == 0)
  89.         continue;
  90.     else
  91.         if ((mresp[0] == '1')|(mresp[0] == '5') )
  92.             cprintf("-- physical-connection established.\n\r");
  93.         else
  94.             cprintf(" Call failed. Modem response=%c\n\r",mresp[0]);
  95.     break;
  96. }
  97.  
  98. if (mresp[0] != '3')
  99.     {
  100. /*--- Initiate Link
  101. */
  102.     cprintf("\n\restablishing MNP link-connection...\n\r");
  103.     wait_a1(19);
  104.     retcode=mnpconnect(5,1,2,0);
  105.     if (retcode == 0)
  106.         {
  107.         _clearscreen(_GCLEARSCREEN);
  108.         cprintf("-- link-connection established.\n\r");
  109.         }
  110.     else
  111.         cprintf("-- link establishment failed. retcode= %i\n\r",retcode);
  112.  
  113. /*--- Start terminal emulation with a clear screen and tell the user
  114. ** how to terminate the program.
  115. */
  116.     if (retcode == 0)
  117.         {
  118.  
  119. /*--- Data phase of Link
  120. */
  121.         wait_a1(80);
  122.         ch=0x3;
  123.         mnpsend(&ch,1);
  124.  
  125.         for (;;)
  126.             {
  127.             mnpstatus(&lstat);
  128.             if (!lstat.p_stat || !lstat.l_stat)
  129.                 {
  130.                 cprintf("\r\n-- link-connection lost\r\n");
  131.                 break;
  132.                 }
  133.             if (lstat.r_cnt > 0)
  134.                 {
  135.                 retcode=mnpreceive(rcv_data,79);
  136.                 for (i = 0; i < retcode; i++)
  137.                     ch=putchar(rcv_data[i]);
  138.                 }
  139.             if (kbhit())
  140.                 {
  141.                 ch=getch();
  142.                 retcode=mnpsend(&ch,1);
  143.                 }
  144.             }
  145.         }
  146. /*--- Exit
  147. */
  148.     cprintf("\n\r-- terminating link-connection...\n\r");
  149.     mnpdisconnect();
  150. }
  151. close_a2(com_port);
  152. cprintf("\n\rend of sample program\n\r");
  153. wait_a1(19);
  154. }
  155.